#include "mypipeuse.hpp"

int main()
{
    srand(time(nullptr)^1024);//种一个随机种子
    std::vector<int> fatherread;//每次父进程创建管道保存下来的读端
    std::vector<channel> channels;//描述每个管道的容器

    //1.初始化
    Initchannels(channels,fatherread);

    
    

    //2.执行任务
    master(channels);

    //3.结束收尾
    //sleep(1);
    for(const auto &e : channels)
    {
        close(e.getfd());
        std::cout << "father close the fd is : " << e.getfd() << 
                        " child pid: "<< e.getid() << std::endl; 
        waitpid(e.getid(), 0, WNOHANG);
    }
    sleep(2);//让父进程多活秒，用于观察
    return 0;
}